package com.wuyou.designPatterns.facade;

import java.io.IOException;
import java.io.Writer;

/**
 * HtmlWriter
 *
 * @Date 2024/10/14 14:30
 * @Author 无忧
 */
public class HtmlWriter {

    private Writer writer;

    public HtmlWriter(Writer writer) {
        this.writer = writer;
    }

    public void title(String title) throws IOException {
        writer.write("<html> \n");
        writer.write("<head> \n");
        writer.write("<title>" + title + "</title> \n");
        writer.write("</head> \n");
        writer.write("<body> \n");
        writer.write("<h1>" + title + "</h1> \n");
    }

    public void paragraph(String msg) throws IOException {
        writer.write("<p>" + msg + "</p> \n");
    }

    public void link(String href, String caption) throws IOException {
        paragraph("<a href=\"" + href + "\">" + caption + "</a>");
    }

    public void mailto(String mailaddr, String username) throws IOException{
        link("mailto:" + mailaddr, username);
    }

    public void close() throws IOException{
        writer.write("</body> \n");
        writer.write("</html>");
        writer.close();
    }
}
